home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-20 | 7.0 KB | 237 lines | [TEXT/ttxt] |
- Example No. 1 - Use of a Logging File.
- ••••••••••••••••••••••••••••••••••••••
-
- on DownLoadMail LogFileName
- Global ActiveService
- --
- -- Attach the logging file to the service and then
- -- execute the service script that reads the mail and
- -- finally detach the logging file.
- -- NB. 'LogFileName' is the full path name of the file to be used.
- --
- set AttachLogFile of window ActiveService to LogFileName
- put ReadMail() into status
- send "DetachLogFile" to window ActiveService
- --
- -- If the reading of the mail went OK (the service handler
- -- returned ‘true’) then ask if its OK to log out otherwise
- -- post an error and logout
- --
- beep
- if not(status) then
- answer "Error detected whilst reading mail" with "Continue”
- end if
- end DownLoadMail
-
-
- o===================================================================o
-
-
- function ReadMail
- Global ActiveService, FoundString
- --
- -- Start the process off by sending a carriage-return to bring up the
- -- menu, and then select the appropriate option to download the mail
- --
- get SendToService(ActiveService, return, "")
- if ExpectFromService(ActiveService, 20, true, true, "Some prompt") then
- if FoundString = 1 then
- get SendToService(ActiveService, "Some Option" & return, "")
- --
- -- Keep reading service until “Terminating prompt” detected
- --
- if ExpectFromService(ActiveService, 300, true, true, "Terminating prompt") then
- if FoundString = 1 then return true
- end if
- end if
- end if
- return false
- end ReadMail
-
-
-
- Example No. 2 - Direct Data Capture.
- ••••••••••••••••••••••••••••••••••••
-
- on CaptureReport
-
- Global ActiveService, FoundString, CapturedData
- --
- -- Step through the various prompts looking for the required one
- -- and then capture data until the terminating prompt is found
- --
- if ExpectFromService(ActiveService, 10, true, true, "Some prompt") then
- if FoundString = 1 then
- get SendToService(ActiveService, "Some command" & return, "")
- --
- -- Found it so capture data now
- --
- put ReceiveFromService(ActiveService, 10, true, true, "Terminating prompt") ¬
- into capturedData
- --
- -- If the string was found then quit the process and return
- -- indicate ‘success’ to the calling code
- --
- if FoundString = 1 then
- get SendToService(ActiveService, "Quit" & return, "")
- return true
- end if
- end if
- end if
- return false
- end CaptureReport
-
-
-
- Example No. 3 - Script Cancelling.
- ••••••••••••••••••••••••••••••••••••
-
- on ExampleHandler
- Global ScriptStatus, AllowCancel, CursorToUse
-
- --
- -- Set the AYS globals for the following enviroment -
- --
- -- Display the special ‘cancel’ cursor whilst searching for strings
- --
- put “cancel” into CursorToUse
- --
- -- Allow cancelling of the ‘search’ functions by the use of the
- -- Command-period key combination but prevent this action also
- -- cancelling the HyperTalk script that is running.
- --
- put true into AllowCancel
- set the cantAbort of this stack to true
- --
- -- Now execute the handler in the desired environment
- --
- put SomeFuction() into reply
- --
- -- Reset the environment
- --
- set the cantAbort of this stack to false
- put “busy” into CursorToUse
- put false into allowCancel
- --
- -- Determine status and react
- --
- -- If the handler did not complete successfully then
- -- determine why it didn’t
- --
- if not(reply) then
- beep
- if ScriptStatus = "Cancel" then
- answer “Cancelling Transfer"
- get CancelFunction()
- else
- answer “Transfer Crashed"
- end if
- end if
- end ExampleHandler
-
-
- Example No. 4 - Character Pair Matching.
- ••••••••••••••••••••••••••••••••••••••••
-
-
- on TransferFile
- Global ActiveService, FoundString, ControlData, DataFileName, CursorToUse
- --
- -- Construct and transmit some machine specific command that starts the
- -- display of some file that we may capture to a logging file etc.
- --
- put "DISPLAY-FILE " & fld "AccountName" & space & fld "FileName" into Command
- if not(SendToService(“TargetMachine”, Command & return, "")) then return false
- --
- -- Now enter a loop that searchs for either -
- -- ‘###’ delimited strings that contain error messages - or
- -- ‘@@@’ delimited strings that contain status messages
- --
- put true into status
- repeat
- if ExpectFromService(TargetMachine, 30, true, true, "###Δ###", "@@@Δ@@@") then
- if FoundString = 0 then
- exit repeat
- end if
- --
- -- Is it an error string, if so display it and exit the loop
- --
- if FoundString = 1 then
- beep
- put "status: " & ExtractMessage(controlData, "###") into fld "Status"
- exit repeat
- end if
- --
- -- Is it an status string, if so display it and then react
- -- according to its contents
- --
- if FoundString = 2 then
- put ExtractMessage(controlData, "@@@") into temp
- put "status: " & temp into fld "Status"
- --
- -- It is an initiate command, start logging the data
- --
- if temp contains "Transfer Initiated" then
- set AttachLogFile of window "TargetMachine" to dataFileName
- put “cancel” into CursorToUse
- end if
- --
- -- If it is a cancel command, set the status flag and exit the loop
- --
- if temp contains "Cancelled" then
- put false into status
- send "DetachLogFile" to window "TargetMachine"
- put “busy” into CursorToUse
- exit repeat
- end if
- --
- -- If it is a completion command, detach the logging file, exit the loop
- --
- if temp contains "Transfer Complete" then
- send "DetachLogFile" to window "TargetMachine"
- put “busy” into CursorToUse
- exit repeat
- end if
- end if
- else
- put false into status
- exit repeat
- end if
- end repeat
- return status
- end TransferFile
-
- o===================================================================o
-
- function ExtractMessage Target, Text
- put the number of chars in Text into xx
- repeat
- put offset(Text, Target) into posn
- if posn = 0 then return(Target)
- delete char posn to (posn+xx) of Target
- end repeat
- end ExtractMessage
-
-
- Example No. 5 - Edit Service Selection.
- •••••••••••••••••••••••••••••••••••••••
-
- on EditServiceText
- Global EditorNames, ActiveService
- --
- -- Select the contents of the terminal emulation screen and then
- -- put the contents into a variable
- --
- send SelectAll to window ActiveService
- put the TerminalSelection of window ActiveService into Text
- --
- -- Create a text edit window called ‘Selected Text’ leaving the window
- -- hidden. Then load the retrieved data and finally show the window
- --
- OpenEditor "Selected Text", false
- if the result = false then exit EditServiceText
-
- set Text of window "Selected Text" to text
- set visible of window "Selected Text" to true
- end EditServiceText
-